package com.cgy.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.cgy.entity.Xibie;
import com.cgy.service.XibieService;

import util.LayuiJsonUtils;


@CrossOrigin
@RestController
@RequestMapping("xibie")
public class xibieController {
	//学生系别接口
		@Autowired
		private XibieService xibieService;
		//动态查询
		@RequestMapping
		public LayuiJsonUtils<Xibie> findAllbyNameXibie(LayuiJsonUtils<Xibie> lj,Xibie x){
			Pageable pageable = PageRequest.of(lj.getPage(), lj.getLimit());
			Page<Xibie> xibie = xibieService.findByxnamePage(x, pageable);
			lj.setData(xibie.getContent());
			lj.setCount(xibie.getTotalElements());
			return lj;
		}
		@RequestMapping("xibieAll")
		public List<Xibie> findAll(){
			
			return xibieService.getAll();
		}
		//增加系别
		@PostMapping
		public Xibie addXibie(Xibie x) {
			return xibieService.addAndUpdate(x);
		}
		//修改
		@PutMapping
		public Xibie updateXibie(Xibie x) {
			return xibieService.addAndUpdate(x);
		}
		
		@DeleteMapping("{xid}")
		public Integer deleteXibie(@PathVariable("xid") Integer xid) {
			return xibieService.deleteXibieByID(xid);
		}
}
